home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / ODF / AMSample / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-06-03  |  9.4 KB  |  342 lines  |  [TEXT/CWIE]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "AMSample.hpp"
  11.  
  12. #ifndef FRAME_H
  13. #include "Frame.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef COMMANDS_H
  21. #include "Commands.h"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. // ----- gadgets -----
  29.  
  30. #ifndef FWBUTTON_H
  31. #include "FWButton.h"
  32. #endif
  33.  
  34. #ifndef FWBUTTON_H
  35. #include "FWButton.h"
  36. #endif
  37.  
  38. #ifndef RECTVIEW_H
  39. #include "RectView.h"
  40. #endif
  41.  
  42. #ifndef PICTVIEW_H
  43. #include "PictView.h"
  44. #endif
  45.  
  46. #ifndef FWLISTBX_H
  47. #include "FWListBx.h"
  48. #endif
  49.  
  50. #ifndef FWCLUSTR_H
  51. #include "FWClustr.h"
  52. #endif
  53.  
  54. #ifndef FWBUTTON_H
  55. #include "FWButton.h"
  56. #endif
  57.  
  58. #ifndef FWEDVIEW_H
  59. #include "FWEdView.h"
  60. #endif
  61.  
  62. // ----- Framework Layer -----
  63.  
  64. #ifndef FWCONTXT_H
  65. #include "FWContxt.h"
  66. #endif
  67.  
  68. #ifndef FWUTIL_H
  69. #include "FWUtil.h"
  70. #endif
  71.  
  72. #ifndef FWPRESEN_H
  73. #include "FWPresen.h"
  74. #endif
  75.  
  76. #ifndef FWSELECT_H
  77. #include "FWSelect.h"
  78. #endif
  79.  
  80. #ifndef FWGROWBX_H
  81. #include "FWGrowBx.h"
  82. #endif
  83.  
  84. #ifndef FWSCLBAR_H
  85. #include "FWSclBar.h"
  86. #endif
  87.  
  88. // ----- OS Layer -----
  89.  
  90. #ifndef FWMENU_H
  91. #include "FWMenu.h"
  92. #endif
  93.  
  94. #ifndef FWEVENT_H
  95. #include "FWEvent.h"
  96. #endif
  97.  
  98. #ifndef FWALERT_H
  99. #include "FWAlert.h"
  100. #endif
  101.  
  102. // ----- Graphic Includes -----
  103.  
  104. #ifndef FWRECT_H
  105. #include "FWRect.h"
  106. #endif
  107.  
  108. #ifndef FWTXTBOX_H
  109. #include "FWTxtBox.h"
  110. #endif
  111.  
  112. #ifndef FWRECSHP_H
  113. #include "FWRecShp.h"
  114. #endif
  115.  
  116. // ----- OpenDoc Includes -----
  117.  
  118. #ifndef SOM_Module_OpenDoc_StdProps_defined
  119. #include <StdProps.xh>
  120. #endif
  121.  
  122. #ifndef SOM_ODDragItemIterator_xh
  123. #include <DgItmIt.xh>
  124. #endif
  125.  
  126. //========================================================================================
  127. // Runtime Information
  128. //========================================================================================
  129.  
  130. #ifdef FW_BUILD_MAC
  131. #pragma segment AMSample
  132. #endif
  133.  
  134. FW_DEFINE_AUTO(CAMSampleFrame)
  135. FW_DEFINE_CLASS_M2(CAMSampleFrame, FW_CFrame, FW_MReceiver)
  136.  
  137. //----------------------------------------------------------------------------------------
  138. // CAMSampleFrame constructor
  139. //----------------------------------------------------------------------------------------
  140. CAMSampleFrame::CAMSampleFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CAMSampleContent* content)
  141.     : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  142.     FW_MDraggableFrame(ev, this),
  143.     FW_MDroppableFrame(ev, this),    
  144.     fAMSampleContent(content)
  145. {
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. // CAMSampleFrame destructor
  150. //----------------------------------------------------------------------------------------
  151.  
  152. CAMSampleFrame::~CAMSampleFrame()
  153. {
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. //    CAMSampleFrame::CanAcceptDrop
  158. //----------------------------------------------------------------------------------------
  159.  
  160. ODDragResult CAMSampleFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
  161. {
  162.     ODDragResult acceptDrop = FW_MDroppableFrame::CanAcceptDrop(ev, dragInfo);
  163.  
  164.     // ----- Test for 'TEXT' also -----
  165. #ifdef FW_BUILD_MAC
  166.     if (!acceptDrop)
  167.     {
  168.         for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
  169.             if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0))    // 'TEXT' on Scrap
  170.                 return TRUE;
  171.     }
  172. #endif
  173.  
  174.     return acceptDrop;
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. //    CAMSampleFrame::DoMouseDown
  179. //----------------------------------------------------------------------------------------
  180.  
  181. FW_Boolean CAMSampleFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  182. {
  183.     FW_Boolean result = FALSE;
  184.  
  185.     if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE))
  186.     {
  187.         result = this->Drag(ev, theMouseEvent);
  188.     }
  189.  
  190.     return result;
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. // CAMSampleFrame::DoMenu
  195. //----------------------------------------------------------------------------------------
  196.  
  197. FW_Boolean CAMSampleFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  198. {
  199.     FW_Boolean menuHandled = TRUE;
  200.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  201.  
  202.     switch (id)
  203.     {
  204.         default:
  205.             menuHandled = FALSE;
  206.     }
  207.  
  208.     return menuHandled;
  209. }
  210.  
  211. //----------------------------------------------------------------------------------------
  212. // CAMSampleFrame::DoAdjustMenus
  213. //----------------------------------------------------------------------------------------
  214.  
  215. FW_Boolean CAMSampleFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  216.                                       FW_Boolean hasMenuFocus,
  217.                                       FW_Boolean isRoot)    // Override
  218. {
  219.     if (hasMenuFocus)
  220.     {
  221.         //---- Set up the Edit menu items ----
  222. #ifdef FW_BUILD_MAC
  223.         menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContents, FW_CPart::gMacTEXTDataType));
  224. #endif
  225.     }
  226.  
  227.     return FALSE;
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. // CAMSampleFrame::Draw
  232. //----------------------------------------------------------------------------------------
  233.  
  234. void CAMSampleFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  235. {
  236.     FW_CViewContext        gc (ev, this, odFacet, invalidShape);
  237.  
  238.     // fill with background color
  239.     FW_CInk        fillInk (FW_CColor (255, 255, 255));    // white
  240.     FW_CRect    bounds = this->GetBounds(ev);    
  241.     FW_CRectShape::RenderRect (gc, bounds, FW_kFill, fillInk);
  242. }
  243.  
  244. //----------------------------------------------------------------------------------------
  245. // CAMSampleFrame::FrameShapeChanged
  246. //----------------------------------------------------------------------------------------
  247. // By default a FW_CFrame view is not refreshed entirely when resized.
  248. // You must decide if your content's appearance depends on the frame's size.
  249. // If it doesn't you don't need to override FrameShapeChanged().
  250. // Here we must redraw the whole frame everytime because the text is centered.
  251.  
  252. void CAMSampleFrame::FrameShapeChanged(Environment* ev)
  253. {
  254.     FW_CFrame::FrameShapeChanged(ev);
  255.  
  256.     this->Invalidate(ev);
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    CAMSampleFrame::NewClipboardCommand
  261. //----------------------------------------------------------------------------------------
  262.  
  263. FW_CClipboardCommand* CAMSampleFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  264. {
  265.     return FW_NEW(CAMSampleEditCommand, (ev, commandID, fAMSampleContent, this));
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. //    CAMSampleFrame::NewDragCommand
  270. //----------------------------------------------------------------------------------------
  271.  
  272. FW_CDragCommand* CAMSampleFrame::NewDragCommand(Environment *ev, 
  273.                                             FW_CFrame* theFrame,
  274.                                             const FW_CMouseEvent& theMouseEvent)
  275. {
  276.     return FW_NEW(CAMSampleDragCommand, (ev, fAMSampleContent, theFrame));
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------
  280. //    CAMSampleFrame::NewDropCommand
  281. //----------------------------------------------------------------------------------------
  282.  
  283. FW_CDropCommand* CAMSampleFrame::NewDropCommand(Environment* ev,
  284.                                              FW_CFrame* frame,
  285.                                              ODDragItemIterator* dropInfo, 
  286.                                              ODFacet* odFacet, 
  287.                                              const FW_CPoint& dropPoint)
  288. {
  289.     return FW_NEW(CAMSampleDropCommand, (ev, fAMSampleContent, this, dropInfo, odFacet, dropPoint));
  290. }
  291.  
  292. //----------------------------------------------------------------------------------------
  293. //    CAMSampleFrame::CreateSubViews
  294. //----------------------------------------------------------------------------------------
  295.  
  296. void CAMSampleFrame::CreateSubViews(Environment* ev)
  297. {
  298.     // WARNING: Make sure that classes created from resources won't be dead-stripped
  299.     //             Use the macro FW_DO_NOT_DEAD_STRIP for those classes which are not 
  300.     //             referenced anywhere else in your part's code.
  301.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  302.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
  303.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);
  304.     FW_DO_NOT_DEAD_STRIP(CContentView);
  305.  
  306.     FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
  307.     FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
  308.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  309.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  310.     FW_DO_NOT_DEAD_STRIP(CRectView);
  311.     FW_DO_NOT_DEAD_STRIP(CPictView);
  312.     FW_DO_NOT_DEAD_STRIP(FW_CListBox);
  313.     FW_DO_NOT_DEAD_STRIP(CRadioGroup);
  314.     FW_DO_NOT_DEAD_STRIP(FW_CGroupBox);
  315.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  316.     FW_DO_NOT_DEAD_STRIP(FW_CRadioCluster);
  317.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  318.     FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
  319.     FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
  320.  
  321.     CreateSubViewsFromResource(ev, kMainWindowResID);
  322. }
  323.  
  324. //----------------------------------------------------------------------------------------
  325. //    CAMSampleFrame::HandleNotification
  326. //----------------------------------------------------------------------------------------
  327.  
  328. void CAMSampleFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
  329. {
  330.     // Handle notification messages for the registered controls.
  331.     // GetMessage() allows to switch on the type of notification.  For each message
  332.     // we can down-cast "notification" directly to the right subclass, without
  333.     // having to use RTTI, because the message is unique to that type.
  334.  
  335.     switch (notification.GetMessage()) 
  336.     {
  337.         default:
  338.             FW_ASSERT("CAMSampleFrame can't respond to this");
  339.             break;
  340.     }
  341. }
  342.